package qrcode;

import java.awt.BorderLayout;
import java.awt.Image;
import java.util.Arrays;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;

public class Test {

  public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        frame.setLayout(new BorderLayout());
        QRCode qr = getQRCode();
        Image image = QRVisualizer.toImage(qr, 4, 12);
        JLabel label = new JLabel(new ImageIcon(image));
        frame.add(label, BorderLayout.CENTER);
        
        frame.pack();
        frame.setVisible(true);
      }
    });
  }
  
  public static QRCode getQRCode(){
    QRCode qr = new QRCode(Version.VERSION_7, ErrorCorrectionLevel.L, DataMaskPattern.MASK_0);
    qr.printToStream(System.out, true);
    System.out.println(qr.getVersion().getNumberOfDataModules());
    
    Boolean[] test = new Boolean[qr.getVersion().getNumberOfDataModules()];
    Arrays.fill(test, Boolean.TRUE);
    
    qr.setDataBits(Arrays.asList(test).iterator());
    qr.printToStream(System.out, true);
    return qr;
  }
}